<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			// 定义一个对象
			function Cat(age){
				this.eat = function(food){
					if(food){
						console.log(food + ' is delicious!');
					}else{
						console.log('nothing to eat!');
					}
				};
				this.sleep = function(){
					console.log('snore...');
				};
				this.miao = function(){
					console.log("I'm " + age + " years old");
				}
				this.gender = 'male';
			}
			
			var cat = new Cat(2);
			console.log(cat.gender);
			cat.gender = 'female';
			console.log(cat.gender);
		</script>
	</head>
	<body>
		<h1>对象初始化</h1>
		<input type="button" value="吃鱼" onclick="cat.eat('fish')"/>
		<input type="button" value="睡觉" onclick="cat.sleep()"/>
		<input type="button" value="喵" onclick="cat.miao()"/>
	</body>
</html>
